{% extends "base.html" %}

{% block content %}
<h1>Account {{ account.title }}</h1>

<p class="description">TODO</p>

<div class="list operation-list">
	<h2>Operations</h2>
	{% if operations %}
		<table class="table-list" cellpadding="0" cellspacing="0">
			<tr class="header">
				<th class="first string operation-status">&nbsp;</th>
				<th class="string operation-followup">!</th>
		    	<th class="string operation-paymode">Paymode</th>
		    	<th class="date operation-date">Date</th>
		    	<th class="string operation-payee">Payee</th>
		    	<th class="string operation-category">Category</th>
		    	<th class="number operation-expense">Expense</th>
		    	<th class="last number operation-income">Income</th>
		    </tr>
			{% for operation in operations %}
				<tr class="{{ loop.cycle('odd', 'even') }}">
			    	<td class="first string operation-status">&nbsp;</td>
					<td class="string operation-followup">&nbsp;</td>
					<td class="string operation-paymode">{{ operation.paymode }}</td>
			    	<td class="date operation-date">{{ operation.date }}</td>
			    	<td class="string operation-payee">{{ operation.payee.title }}</td>
			    	<td class="string operation-category">{{ operation.category.title }}</td>
			    	<td class="number operation-expense">{%if operation.expense > 0 %}{{ operation.expense|float(0.00) }} &euro;{% endif %}</td>
			    	<td class="last number operation-income">{%if operation.income > 0 %}{{ operation.income|float(0.00) }} &euro;{% endif %}</td>
			    </tr>
			{% endfor %}
			<tr class="footer">
				<td colspan="8" class="first last operations-total">Account Balance: TODO &euro;</td>
			</tr>
		</table>
	{% endif %}
</div>

{% macro input(name, value='', type='text', id='') -%}
	<input type="{{ type }}" name="{{ name }}" value="{{ value|e }}" id="{{ id }}" />
{%- endmacro %}
<form action="view?key={{ account.key() }}" method="post">
	<table cellpadding="0" cellspacing="5">
        <tr>
            <th>Paymode</th>
            <td>
            	<select name="paymode">
            		<option value="CB" {% if operation and operation.paymode == 'CB' %}selected="selected"{% endif %}>CB</option>
            		<option value="CHEQUE" {% if operation and operation.paymode == 'CHEQUE' %}selected="selected"{% endif %}>CHEQUE</option>
            		<option value="TIP" {% if operation and operation.paymode == 'TIP' %}selected="selected"{% endif %}>TIP</option>
            	</select>
            	<input type="text" name="paymode_note" value="{% if operation %}{{ operation.paymode_note }}{% endif %}" />
                {% if 'paymode' in errors %}<span class="error">{{ errors.paymode }}</span>{% endif %}
            </td>
        </tr>
        <tr>
            <th>Date</th>
            <td>
            	{{ input('date', '') }}
                {% if 'date' in errors %}<span class="error">{{ errors.date }}</span>{% endif %}
            </td>
        </tr>
        <tr>
            <th>Payee</th>
            <td>
            	<select name="payee">
            		{% for payee in payees %}
            			<option value="{{ payee.key() }}" {% if operation and operation.payee == payee.key() %}selected="selected"{% endif %}>{{ payee.title }}</option>
           			{% endfor %}
            	</select>
                {% if 'payee' in errors %}<span class="error">{{ errors.payee }}</span>{% endif %}
            </td>
        </tr>
        <tr>
            <th>Category</th>
            <td>
                <select name="category">
            		{% for category in categories %}
            			<option value="{{ category.key() }}" {% if operation and operation.category == category.key() %}selected="selected"{% endif %}>{{ category.title }}</option>
           			{% endfor %}
            	</select>
            	{% if 'category' in errors %}<span class="error">{{ errors.category }}</span>{% endif %}
            </td>
        </tr>
        <tr>
            <th>Expense</th>
            <td>
                <input type="text" name="expense" value="{% if operation %}{{ operation.expense }}{% endif %}" />
                {% if 'expense' in errors %}<span class="error">{{ errors.expense }}</span>{% endif %}
            </td>
        </tr>
        <tr>
            <th>Income</th>
            <td>
                <input type="text" name="income" value="{% if operation %}{{ operation.income }}{% endif %}" />
                {% if 'income' in errors %}<span class="error">{{ errors.income }}</span>{% endif %}
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" name="cancel" value="Cancel" />
                <input type="submit" value="Submit" />
            </td>
        </tr>
	</table>
</form>

{% endblock %}
